const createSitemapRoutes = async () => {
  const routes = []
  const { $content } = require('@nuxt/content')
  globalThis.posts = await $content('articles').fetch()
  for (const post of globalThis.posts) {
    routes.push(`article/${post.slug}`)
  }
  return routes
}
export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    titleTemplate: '癸 - %s',
    htmlAttrs: {
      lang: 'zh-CN',
    },
    meta: [
      { charset: 'utf-8' },
      {
        name: 'viewport',
        content:
          'width=device-width, initial-scale=1,minimum-scale=1.0,viewport-fit=cover',
      },
      {
        hid: 'description',
        name: 'description',
        content: '全世界的切图仔联合起来。',
      },
      {
        hid: 'keywords',
        name: 'keywords',
        content:
          '切图仔 前端 小程序 可视化 curd boy vue nuxt next react vite webpack nest typescript electron 个人网站 博客 markdown 技术分享 个人博客 服务端渲染 单页应用 前端技术 Rust学习 打包配置 入门指南 开源项目',
      },
      { name: 'format-detection', content: 'telephone=no' },
      { name: 'color-scheme', content: 'light dark' },
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: ['./assets/css/pure.css', './assets/css/sight.css'],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [{ src: './plugins/theme.js', mode: 'client' }],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/eslint
    '@nuxtjs/eslint-module',
    // https://go.nuxtjs.dev/stylelint
    '@nuxtjs/stylelint-module',
    '@nuxt/postcss8',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: ['@nuxtjs/i18n', '@nuxtjs/sitemap', '@nuxt/content'],
  server: {
    host: '0.0.0.0',
    port: 3001,
  },
  sitemap: {
    path: '/sitemap.xml',
    exclude: ['/404'],
    gzip: true,
    hostname: 'https://www.wissbell.com',
    routes: createSitemapRoutes,
    defaults: {
      changefreq: 'daily',
      priority: 1,
      lastmod: new Date(),
    },
  },
  i18n: {
    locales: [
      {
        name: 'ENGLISH',
        code: 'en-US',
        file: 'en-US.js',
      },
      {
        name: '简体中文',
        code: 'zh-CN',
        file: 'zh-CN.js',
      },
    ],
    lazy: true,
    langDir: 'lang/',
    defaultLocale: 'zh-CN',
  },
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {},
  content: {
    markdown: {
      tocDepth: 5,
    },
  },
  publicRuntimeConfig: {
    STATIC_BASE:
      process.env.NODE_ENV === 'production'
        ? 'https://static.wissbell.com/wissbell'
        : 'http://localhost:3001',
    STATIC_CLIP:
      process.env.NODE_ENV === 'production' ? '?imageMogr2/format/webp' : '',
  },
}
